package com.rocky.practice.instrument;

import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;

import java.util.List;


public class AttachMain {
    public static void main(String[] args) {
        /*List<VirtualMachineDescriptor> vms = VirtualMachine.list();
        for (VirtualMachineDescriptor vm : vms) {
            System.out.println(vm.displayName());
        }*/
        try {
            VirtualMachine attach = VirtualMachine.attach("8840");
            attach.loadAgent("D:\\IdeaProjects\\java_practice_public\\instrument\\instrument_project\\target\\instrument_project-1.0-SNAPSHOT-jar-with-dependencies.jar");
            Thread.sleep(1000000);
            attach.detach();
            System.out.println("detached");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
